//
//  CertificationViewController.m
//  Yihubang
//
//  Created by xmy on 16/8/28.
//  Copyright © 2016年 jinghao. All rights reserved.
//

#import "CertificationViewController.h"
#import "CertificationViewModel.h"
@interface CertificationViewController ()
@property (nonatomic , strong) CertificationViewModel * viewModel;
@end

@implementation CertificationViewController
@synthesize viewModel = _viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.viewModel.title = @"实名认证";
    self.showLeftMenu =YES;
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"认证" style:UIBarButtonItemStylePlain target:self action:@selector(Certification:)] animated:TRUE];
    //    self.view.backgroundColor = [UIColor colorWithHex:0xF7F7F7];
    self.identification_text.maxLenght = 18;
    [self.name_text becomeFirstResponder];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void) viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    //    self.iconWidth_contant.constant = RatioBase6(100);
}
- (void)bindViewModel
{
    [super bindViewModel];
     @weakify(self)
    //绑定数据
    RAC(self.viewModel, name) = self.name_text.rac_textSignal;
    RAC(self.viewModel, identification) = self.identification_text.rac_textSignal;
    RAC(self.navigationItem.rightBarButtonItem,enabled) = self.viewModel.validsaveSignal;
    [RACObserve(self.viewModel,updateidentificationImg)subscribeNext:^(NSNumber*signupActive){
        @strongify(self)
        if([signupActive boolValue]){
            self.indentification_image.userInteractionEnabled =NO;
        }else{
            self.indentification_image.userInteractionEnabled =YES;
        }
    }];
    [RACObserve(self.indentification_image,userInteractionEnabled) subscribeNext:^(NSNumber*signupActive){
        @strongify(self)
        if([signupActive boolValue]){
            self.updateAgain.hidden =YES;
        }else{
             self.updateAgain.hidden =NO;
        }
    }];
    [[self.updateAgain rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         @strongify(self)
         [self.viewModel.updateAgainCommand execute:self.indentification_image];
     }];
    [self.indentification_image setTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        @strongify(self)
        [self.viewModel.updateAgainCommand execute:self.indentification_image];
    }];
//    [[self.indentification_image rac_signalForControlEvents:UIControlEventTouchUpInside]
//     subscribeNext:^(id x) {
//         @strongify(self)
//         [self.viewModel.updateAgainCommand execute:x];
//     }];
}
-(void)Certification :(id)sender{
    [self.viewModel.saveCommand execute:self.indentification_image];
}
#pragma mark --

- (CertificationViewModel*)viewModel{
    if (!_viewModel) {
        _viewModel = [[CertificationViewModel alloc] initWithViewController:self];
    }
    return _viewModel;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
